var app = getApp();
let PAGESIZE = 20;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [], //列表
    empty: '', //空数据
    noData: false,
    loadmore: false,
    nomore: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.page = 1;
    this.getList();
  },

  onPullDownRefresh: function () {
    this.page = 1;
    this.setData({
      list: [],
      nomore: false,
      loadmore: false,
    })
    this.getList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.loadmore) {
      ++this.page;
      this.getList();
    }
  },



  // 获取列表
  getList() {
    app.ajax({
      url: 'Common/Version/getVersion',
      data: {
        page: this.page,
        limit: PAGESIZE,
        search: {
          client: 3
        }
      },
      success: res => {
        wx.stopPullDownRefresh()
        if (res.data.code == 1000) {
          const source = res.data.data;
          let list = this.data.list.concat(source);
          let nomore = false,
            loadmore = false;
          if (source.length < PAGESIZE) {
            nomore = true;
          } else {
            loadmore = true;
          }
          this.setData({
            empty: false,
            loadmore,
            nomore,
            list
          })
        } else {
          if (this.page == 1) {
            this.setData({
              empty: true
            })
          } else {
            this.setData({
              loadmore: false,
              nomore: true,
            })
          }
        }
      },
      error: e => {
        wx.stopPullDownRefresh()
        app.showToast("网络错误");
      }
    })
  },
  // 跳转详情
  goDetail(e) {
    wx.navigateTo({
      url: '../detail/detail?id=' + e.currentTarget.dataset.id + '&title=版本更新说明',
    })
  }

})